﻿using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Web.UI.WebControls;

using IdeaNMR.Web.Core;
using IdeaNMR.Shared;
using IdeaNMR.Shared.Utils;

namespace IdeaNMR.Web
{
    /// <summary>
    /// The page allows user to browse, add, modify and delete his/her spectrometers.
    /// </summary>
    /// <remarks>
    /// The main content is located in a MultiView mvCategories
    /// that has 3 views
    /// <list type="">
    /// <item>
    /// To display all spectrometers in a GridView gvAllSpectrometers
    /// </item>
    /// <item>
    /// To show a single spectrometer in a form
    /// </item>
    /// <item>
    /// Provides a form to add or modify a spectrometer
    /// </item>
    /// </list>
    /// The request parameter TargetID specifies which spectrometer to display.
    /// When page is new, the first view is displayed if TargetID is not specified.
    /// Alternatively the second view is displayed with the spectrometer with TargetID.
    /// </remarks>
    public partial class MySpectrometers : IdeaNMR_BasePage
    {
        #region Page Lifecycle
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) return;
           
            this.Master.Title = "My Spectrometers";
        }

        #endregion

        #region Event Handlers
        protected void SpecTable_OnSelected(object sender, IdeaNMR.Web.ItemSelectedCommandEventArgs e)
        {
            UriBuilder uri = new UriBuilder(ScrewTurnWikiFacade.MainUrl);
            uri.Path += "Spectrometer_New.ashx";
            uri.AddQueryParameter("TargetID", e.SelectedItem.Id.ToString());

            this.RedirectParent(uri.Uri);
        }

        /// <summary>
        /// When Add Button is clicked show the form to add new spectrometer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btAddSpectrometer_Click(object sender, EventArgs e)
        {
            UriBuilder uri = new UriBuilder(ScrewTurnWikiFacade.MainUrl);
            uri.Path += "Spectrometer_New.ashx";

            this.RedirectParent(uri.Uri);
        }
        #endregion
    }
}